/* GUI CONVERTED from ecmt07.p (converter v1.76) Wed May 28 02:21:18 2003 */
/* ecmt07.p - ECN MAINTENANCE Add, Modify, Deactivate Product Structures      */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.13.1.12 $                                                           */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.4      LAST MODIFIED: 08/16/93   BY: qzl *H013*                */
/* REVISION: 7.4      LAST MODIFIED: 08/16/93   BY: qzl *H343*                */
/* REVISION: 7.4      LAST MODIFIED: 09/01/94   BY: qzl *H499*                */
/* REVISION: 7.4      LAST EDIT:     10/27/94   MODIFIED BY: ame *H578*       */
/* REVISION: 7.4      LAST MODIFIED: 03/22/95   by: srk *H0C4*                */
/* REVISION: 7.4      LAST MODIFIED: 05/04/95   BY: qzl *H0DB*                */
/* REVISION: 7.4      LAST MODIFIED: 11/16/95   BY: bcm *H0H3*                */
/* REVISION: 7.4      LAST MODIFIED: 12/19/95   BY: bcm *H0HR*                */
/* REVISION: 7.4      LAST MODIFIED: 12/30/95   BY: qzl *H0J1*                */
/* REVISION: 7.4      LAST MODIFIED: 07/31/96   BY: *G2B7* Julie Milligan     */
/* REVISION: 8.6      LAST MODIFIED: 12/05/96   BY: Joe Gawel *K00C*          */
/* REVISION: 7.4      LAST MODIFIED: 01/23/97   BY: *H0QG* Russ Witt          */
/* REVISION: 8.6      LAST MODIFIED: 07/03/97   BY: Joe Gawel    *K0F6*       */
/* REVISION: 8.6      LAST MODIFIED: 07/09/97   BY: *H1BP* Felcy D'Souza      */
/* REVISION: 8.6      LAST MODIFIED: 08/13/97   BY: Joe Gawel    *K0H5*       */
/* REVISION: 8.6      LAST MODIFIED: 10/07/97   BY: John Worden  *K0LP*       */
/* REVISION: 8.6      LAST MODIFIED: 01/12/98   BY: *H1G3*  Manmohan Pardesi  */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 06/25/99   BY: *J3H5* Jyoti Thatte       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/08/00   BY: *M0QY* Mark Christian     */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00   BY: *N0KW* Jacolyn Neder      */
/* REVISION: 9.1      LAST MODIFIED: 08/24/00   BY: *N0MZ* Mudit Mehta        */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.13.1.11  BY: Mark Christian     DATE: 07/03/01  ECO: *M1CX*   */
/* $Revision: 1.13.1.12 $   BY: K Paneesh        DATE: 05/27/03  ECO: *P0T5*   */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

   /*NOTE: prog_type:                                             */
   /*      T-09 : ADD ITEM TO PRODUCT STRUCTURES                  */
   /*      T-10 : EDIT PRODUCT STRUCTURE DATA                     */
   /*      T-12 : DEACTIVATE PRODUCT STRUCTURE RECORD             */
   /*      T-21 : ADD ITEM TO FORMULAE                            */
   /*      T-22 : EDIT FORMULAE DATA                              */
   /*      T-24 : DEACTIVATE FORMULAE RECORD                      */
   /* THE PROCESSING OF THE RECORDS HAVE BEEN COMBINED TO    */
   /* ONLY USE ON PROG_TYPE IN 8.6 AND THEREFORE prog_type   */
   /* FOR T-10, T-12, T-22 AND T-24 HAVE BEEN OBSOLETED.     */

{mfdeclre.i}
{pxmaint.i}

{pxphdef.i pspl}

/* EXTERNAL LABEL INCLUDE */
{gplabel.i}
/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE ecmt07_p_1 "Comments"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define new shared variable ps_recno as recid.
define new shared variable ps_ok like mfc_logical no-undo.
define new shared variable cmtindx as integer.

define variable ecd1par   like ecd1_par  no-undo.
define variable ecd1comp  like ecd1_comp no-undo.
define variable ecd1ref   like ecd1_ref  no-undo.
define variable ecd1qad01 like ecd1__qad01 initial no no-undo.
define variable ph        like mfc_logical no-undo.
define variable del-yn    like mfc_logical initial no no-undo.
define variable goon-yn   like mfc_logical initial no no-undo.
define variable msg-type  as integer no-undo.
define variable l-um      like pt_um no-undo.
define variable conv      like ps_um_conv initial 1 no-undo.
define variable batch_um  like bom_batch_um no-undo.
define variable psmand    like ps_mandatory no-undo.
define variable psdflt    like ps_default   no-undo.
define variable ecd1new   like mfc_logical  no-undo.
define variable formula   like bom_formula  no-undo.
define variable deact     as logical        no-undo.
define variable ecdcmmts  like mfc_logical initial no
                          label {&ecmt07_p_1} no-undo.
define variable par_desc  like pt_desc1.
define variable comp_desc like pt_desc1.
define variable true1     like mfc_logical initial yes no-undo.
define variable false1    like mfc_logical initial no no-undo.
define variable batch_size  like bom_batch    no-undo.
define variable bombatch    like bom_batch    no-undo.
define variable bombatchum  like bom_batch_um no-undo.
define variable l-msg2 like msg_desc no-undo.
define variable l-msg3 like msg_desc no-undo.
define variable l-msg4 like msg_desc no-undo.

define workfile ph_par field phpar like ps_par.
define workfile ph_comp field phcomp like ps_comp.
define workfile ec_parent
   field ec_par like ecd1_par.

define buffer ecmmstr for ecm_mstr.
define buffer ecd1 for ecd1_det.

{ecmtparm.i}

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
{ecform06.i}
 SKIP(.4)  /*GUI*/
with frame form06 width 80 side-labels attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-form06-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame form06 = F-form06-title.
 RECT-FRAME-LABEL:HIDDEN in frame form06 = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame form06 =
  FRAME form06:HEIGHT-PIXELS - RECT-FRAME:Y in frame form06 - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME form06 = FRAME form06:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame form06:handle).

/* ITEM NUMBER OR BOM CODE MUST EXIST */
{pxmsg.i &MSGNUM=231  &ERRORLEVEL=3 &MSGBUFFER=l-msg3}

/* INVALID QUANTITY TYPE */
{pxmsg.i &MSGNUM=6910 &ERRORLEVEL=3 &MSGBUFFER=l-msg2}

/* PERCENTAGE MUST BE IN THE RANGE: 0 - 100 */
{pxmsg.i &MSGNUM=3745 &ERRORLEVEL=3 &MSGBUFFER=l-msg4}

view frame form06.
assign
   ecd1par  = ""
   ecd1comp = "".

find ecm_mstr where recid(ecm_mstr) = ecm_recid no-lock no-error.
if not available (ecm_mstr) then do:
   assign
      msgnbr = 5630
      warnlvl = 2.
   return.
end. /* IF NOT AVAILABLE (ecm_mstr) */

mainloop:
repeat with frame form06:
/*GUI*/ if global-beam-me-up then undo, leave.


   if (prog_type = "T-21") then
      formula = yes.
   else
      formula = no.
   assign
      ecd1new = no
      psmand = yes
      psdflt = yes
      ph = no
      ecdcmmts = no.

   update
      ecd1par  validate({psval.v ecd1par}, l-msg3)
      ecd1comp validate({psval.v ecd1comp}, l-msg3)
      ecd1ref
      with frame form06
   editing:

      if frame-field = "ecd1par" then do:
         /* FIND PRE/NEXT */
         {mfnp05.i ecd1_det ecd1_par_comp
            "(ecd1_nbr = ecm_nbr)" ecd1_par "input ecd1par"}

         if recno <> ? then do:
            assign
               l-um      = ""
               par_desc  = ""
               comp_desc = "".
            find bom_mstr where bom_par = ecd1_par no-lock no-error.
            if available bom_mstr and bom_desc <> "" then
               assign
                  bombatch = bom_batch
                  bombatchum = bom_batch_um
                  par_desc = bom_desc.
            else do:
               find pt_mstr where pt_part = ecd1_par
                  no-lock no-error.
               if available pt_mstr then
                  assign
                     bombatch = 1
                     bombatchum = pt_um
                     par_desc = pt_desc1.
            end. /* ELSE */

            /* GET THE COMPONENT UM AND DESCRIPTION */
            {pxrun.i &PROC    = 'get_um_desc_data'
                     &PROGRAM = 'pspl.p'
                     &HANDLE  = ph_pspl
                     &PARAM   = "(
                                input  ecd1_comp,
                                output l-um,
                                output comp_desc
                              )"
            }

            display
               ecd1_par    @ ecd1par
               par_desc
               ecd1_comp   @ ecd1comp
               comp_desc
               ecd1_ref    @ ecd1ref
               bombatch    when (formula)
               bombatchum  when (formula)
               ecd1__qad01 @ ecd1qad01
               ecd1_qty_per_b
               l-um @ pt_um
               ecd1_scrp_pct
               ecd1_qty_type
               ecd1_batch_pct
               ecd1_op
               ecd1_item_no
               ecd1__qad03
               false1 when (ecd1__qad04 = "0") @ psmand
               true1  when (ecd1__qad04 <> "0") @ psmand
               false1 when (ecd1__qad05 = "0") @ psdflt
               true1  when (ecd1__qad05 <> "0") @ psdflt
               ecd1_rmks
               true1  when (ecd1_cmtindx <> 0) @ ecdcmmts
               false1 when (ecd1_cmtindx = 0) @ ecdcmmts
               ecd1_lt_off
               ecd1_fcst_pct
               ecd1_group
               ecd1_psprocess
            with frame form06.

            if formula and not available bom_mstr then do:
               find pt_mstr where pt_part = ecd1_par
                  no-lock no-error.
               assign
                  bombatch = 1
                  bombatchum = pt_um.
               display
                  bombatch
                  bombatchum
               with frame form06.
            end. /* IF formula */

         end. /* IF recno <> ? */

      end. /* IF FRAME-FIELD = "ecd1par" */

      else
      if frame-field = "ecd1comp" then
      do on endkey undo mainloop, leave mainloop:

         /* FIND PRE/NEXT */
         {mfnp05.i ecd1_det ecd1_par_comp
            "(ecd1_nbr = ecm_nbr and ecd1_par = input ecd1par)" ecd1_comp
            "input ecd1comp"}

         if recno <> ? then do:
            assign
            l-um      = ""
            comp_desc = "".


            /* GET THE COMPONENT UM AND DESCRIPTION */
            {pxrun.i &PROC    = 'get_um_desc_data'
                     &PROGRAM = 'pspl.p'
                     &HANDLE  = ph_pspl
                     &PARAM   = "(
                                input  ecd1_comp,
                                output l-um,
                                output comp_desc
                              )"
            }
            display
               ecd1_comp @ ecd1comp
               comp_desc
               ecd1_ref  @ ecd1ref
               ecd1__qad01 @ ecd1qad01
               ecd1_qty_per_b
               l-um @ pt_um
               ecd1_scrp_pct
               ecd1_qty_type
               ecd1_batch_pct
               ecd1_op
               ecd1_item_no
               ecd1__qad03
               no  when (ecd1__qad04 = "0") @ psmand
               yes when (ecd1__qad04 <> "0") @ psmand
               no  when (ecd1__qad05 = "0") @ psdflt
               yes when (ecd1__qad05 <> "0") @ psdflt
               ecd1_rmks
            with frame form06.

         end. /* IF recno <> ? */

      end. /* IF FRAME-FIELD = "ecd1comp" */
      else do:
         readkey.
         apply lastkey.
      end. /* ELSE */

   end. /* UPDATE WITH FRAME form06 EDITING */

   /* ENSURES THAT ALTERNATE PRODUCT STRUCTURES ARE NOT MODIFIED */
   if (can-find(first ps_mstr
   where ps_par     = ecd1par
   and   ps_comp    = ecd1comp
   and   ps_ref     = ecd1ref
   and   ps_ps_code = "A"))
   then do:

      /* ALTERNATE STRUCTURE NOT ALLOWED */
      {pxmsg.i &MSGNUM=598 &ERRORLEVEL=3}
      undo, retry.

   end. /* IF AVAILABLE ps_mstr */

   if formula then do:

      find bom_mstr where bom_parent = ecd1par no-lock no-error.

      if available bom_mstr then do:
         assign
            bombatch = bom_batch
            bombatchum = bom_batch_um.
         display
            bombatch
            bombatchum
         with frame form06.
         batch_size = bom_batch.
      end. /* IF AVAILABLE bom_mstr */

      else do:
         find pt_mstr no-lock where pt_part = ecd1par no-error.
         if available pt_mstr then do:
            assign
               bombatch = 1
               bombatchum = pt_um.
            display
               bombatch
               bombatchum
            with frame form06.
            batch_size = bombatch.
         end. /* IF AVAILABLE pt_mstr */
      end. /* ELSE */

   end. /* IF formula */

   find first ecd1_det where ecd1_nbr = ecm_nbr
      and ecd1_par = ecd1par and ecd1_comp = ecd1comp
      and ecd1_ref = ecd1ref no-lock no-error.
   if available ecd1_det then
      ecd1qad01 = ecd1__qad01.
   else
      ecd1qad01 = no.
   update ecd1qad01 with frame form06.
   deact = input ecd1qad01.

   find ecd1_det where ecd1_nbr = ecm_nbr and ecd1_par = ecd1par
      and ecd1_comp = ecd1comp and ecd1_ref = ecd1ref no-error.
   if locked(ecd1_det) then do:
      assign
         msgnbr = 7422
         warnlvl = 4.
      return.
   end. /* IF LOCKED(ecd1_det) */
   else if not available ecd1_det then do:

      if ecd1par  = ecd1comp  then do:
         /* CYCLIC STRUCTURE NOT ALLOWED */
         {pxmsg.i &MSGNUM=206 &ERRORLEVEL=3}
         undo, retry.
      end. /* IF ecd1par = ecd1comp */

      find bom_mstr no-lock where bom_parent = ecd1par no-error.
      if available bom_mstr and bom_formula then formula = yes.
      else do:
         find pt_mstr no-lock where pt_part = ecd1par no-error.
         if available pt_mstr and pt_formula then formula = yes.
      end. /* ELSE */

      if (prog_type = "T-09") and formula then do:
         /* FORMULA CONTROLLED */
         {pxmsg.i &MSGNUM=263 &ERRORLEVEL=3}
         undo, retry.
      end.

      /* ADDING NEW RECORD */
      {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}

      create ecd1_det.
      assign
         ecd1_nbr      = ecm_nbr
         ecd1_par      = ecd1par
         ecd1_comp     = ecd1comp
         ecd1_ref      = ecd1ref
         ecd1__qad04   = "1"
         ecd1__qad05   = "1"
         ecd1_mod_date = today.

      if not deact then ecd1__qad01 = no.
      ecd1new = yes.

   end. /* ELSE IF NOT AVAILABLE ecd1_det */

   else do:

      find bom_mstr no-lock where bom_parent = ecd1_par no-error.
      if available bom_mstr and bom_formula then formula = yes.
      else do:
         find pt_mstr no-lock where pt_part = ecd1_par no-error.
         if available pt_mstr and pt_formula then formula = yes.
      end. /* ELSE */

      if ecd1_qty_type = "P" and  not formula then do:
         /* PERCENT OF BATCH STRUCTURE */
         {pxmsg.i &MSGNUM=4604 &ERRORLEVEL=3}
         undo mainloop, retry.
      end. /* IF ecd1_qty_type = "P" */

      if (prog_type = "T-09") and formula then do:
         /* FORMULA CONTROLLED */
         {pxmsg.i &MSGNUM=263 &ERRORLEVEL=3}
         undo, retry.
      end. /* IF (prog_type = "T-09" */

   end. /* ELSE */

   assign
      recno = recid(ecd1_det)
      par_desc = ""
      comp_desc = "".

   find bom_mstr where bom_par = ecd1_par no-lock no-error.
   if available bom_mstr and bom_desc <> "" then par_desc = bom_desc.
   else do:
      find pt_mstr where pt_part = ecd1_par no-lock no-error.
      if available pt_mstr then par_desc = pt_desc1.
   end. /* ELSE */


            /* GET THE COMPONENT UM AND DESCRIPTION */
            {pxrun.i &PROC    = 'get_um_desc_data'
                     &PROGRAM = 'pspl.p'
                     &HANDLE  = ph_pspl
                     &PARAM   = "(
                                input  ecd1_comp,
                                output l-um,
                                output comp_desc
                              )"
            }
   display
      par_desc
      comp_desc
   with frame form06.

   find ps_mstr where
      ps_par = ecd1par and
      ps_comp = ecd1comp and
      ps_ref = ecd1ref and
      (ps_start <= today or ps_start = ?) and
      (ps_end >= today or ps_end = ?)
      no-lock no-error.

   if not available ps_mstr and new(ecd1_det) then
   ph-test:
   do on endkey undo mainloop, retry mainloop:

      for each ph_par exclusive-lock:
         delete ph_par.
      end. /* FOR EACH ph_par */

      for each ph_comp exclusive-lock:
         delete ph_comp.
      end. /* FOR EACH ph_comp */

      find first ps_mstr where
         ps_par = ecd1par and
         ps_ref = ecd1ref and
         (ps_start <= today or ps_start = ?) and
         (ps_end >= today or ps_end = ?)
         no-lock no-error.

      if not available ps_mstr then leave ph-test.

      find first ps_mstr where
         ps_comp = ecd1comp and
         ps_ref = ecd1ref and
         (ps_start <= today or ps_start = ?) and
         (ps_end >= today or ps_end = ?)
         no-lock no-error.
      if not available ps_mstr then leave ph-test.

      for each ps_mstr where
         ps_par = ecd1par and
         ps_ref = ecd1ref and
         (ps_start <= today or ps_start = ?) and
         (ps_end >= today or ps_end = ?)
         no-lock:

         create ph_comp.
         phcomp = ps_comp.

      end. /* FOR EACH ps_mstr */

      for each ps_mstr where
         ps_comp = ecd1comp and
         ps_ref = ecd1ref and
         (ps_start <= today or ps_start = ?) and
         (ps_end >= today or ps_end = ?)
         no-lock:

         create ph_par.
         phpar = ps_par.

      end. /* FOR EACH ps_mstr */

      for each ph_par, each ph_comp:
/*GUI*/ if global-beam-me-up then undo, leave.


         ph = no.

         if phpar = phcomp then do:

            find pt_mstr where pt_part = phpar no-lock no-error.
            if not available pt_mstr then do:
               ph = yes.
            end. /* IF NOT AVAILABLE pt_mstr */
            else do:
               find first ptp_det where ptp_part = phpar
                  no-lock no-error.
               if available ptp_det and ptp_phantom = yes then
                  ph = yes.
               else do:
                  find pt_mstr where pt_part = phpar
                     no-lock no-error.
                  if available pt_mstr and pt_phantom = yes then
                     ph = yes.
               end. /* ELSE */
            end. /* ELSE */

            find ps_mstr where
               ps_par = ecd1par and
               ps_comp = phcomp and
               ps_ref = ecd1ref and
               (ps_start <= today or ps_start = ?) and
               (ps_end >= today or ps_end = ?)
               no-lock no-error.

            if available ps_mstr and ps_ps_code = "X" then
               ph = yes.

            find ps_mstr where
               ps_par = phpar and
               ps_comp = ecd1comp and
               ps_ref = ecd1ref and
               (ps_start <= today or ps_start = ?) and
               (ps_end >= today or ps_end = ?)
               no-lock no-error.

            if available ps_mstr and ps_ps_code = "X" then
               ph = yes.

            if ph then do on endkey undo mainloop, retry mainloop:
               goon-yn = no.
               hide message.
               /* PHANTOM EXISTS BETWEEN PARENT AND COMPONENT */
               {pxmsg.i &MSGNUM=5643 &ERRORLEVEL=2 &CONFIRM=goon-yn}
               if not goon-yn then undo mainloop, retry mainloop.
               else leave.
            end. /* IF ph */

         end. /* IF phpar = phcomp */

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR EACH ph_par, EACH ph_comp: */

   end. /* DO ON ENDKEY UNDO mainloop, RETRY mainloop */

   /*STRUCTURE RELEASED ON ANOTHER ECN, BUT NOT IMPLEMENTED*/
   /*USE DATA FROM LAST RELEASED ECN TO CREATE NEW ECN*/
   /*OTHERWISE USE LAST INCORPORATED ECN*/
   if ecd1new then do for ecd1, ecmmstr:
      for each ecmmstr no-lock where
             ecmmstr.ecm_end_date = ?
         and ecmmstr.ecm_rel_date <> ?,
         each ecd1 no-lock where
             ecd1.ecd1_nbr = ecmmstr.ecm_nbr
         and ecd1.ecd1_par = ecd1_det.ecd1_par
         and ecd1.ecd1_comp = ecd1_det.ecd1_comp
         and ecd1.ecd1_ref = ecd1_det.ecd1_ref
         by ecm_rel_date descending:
         leave.
      end. /* FOR EACH ecmmstr */

      if available ecd1 then do:

         assign
            ecd1_det.ecd1_item_no   = ecd1.ecd1_item_no
            ecd1_det.ecd1_op        = ecd1.ecd1_op
            ecd1_det.ecd1_qty_per_b = ecd1.ecd1_qty_per_b
            ecd1_det.ecd1_rmks      = ecd1.ecd1_rmks
            ecd1_det.ecd1_scrp_pct  = ecd1.ecd1_scrp_pct
            ecd1_det.ecd1__qad03    = ecd1.ecd1__qad03
            ecd1_det.ecd1__qad04    = ecd1.ecd1__qad04
            ecd1_det.ecd1__qad05    = ecd1.ecd1__qad05
            ecd1_det.ecd1_lt_off    = ecd1.ecd1_lt_off
            ecd1_det.ecd1_fcst_pct  = ecd1.ecd1_fcst_pct
            ecd1_det.ecd1_group     = ecd1.ecd1_group
            ecd1_det.ecd1_psprocess = ecd1.ecd1_psprocess.

         if formula then
            ecd1_det.ecd1_batch_pct = ecd1.ecd1_batch_pct.

      end. /* IF AVAILABLE ecd1 */

      else do:

         find last ps_mstr no-lock where
            ps_par = ecd1_det.ecd1_par
            and ps_comp = ecd1_det.ecd1_comp
            and ps_ref = ecd1_det.ecd1_ref
            and (ps_end >= today or ps_end = ?)
            no-error.

         if available ps_mstr then do:

            assign
               ecd1_det.ecd1_item_no   = ps_item_no
               ecd1_det.ecd1_op        = ps_op
               ecd1_det.ecd1_qty_per_b = ps_qty_per_b
               ecd1_det.ecd1_rmks      = ps_rmks
               ecd1_det.ecd1_scrp_pct  = ps_scrp_pct
               ecd1_det.ecd1__qad03    = ps_ps_code
               psmand                  = ps_mandatory
               psdflt                  = ps_default
               ecd1_det.ecd1_lt_off    = ps_lt_off
               ecd1_det.ecd1_fcst_pct  = ps_fcst_pct
               ecd1_det.ecd1_group     = ps_group
               ecd1_det.ecd1_psprocess = ps_process.

            if formula then
               ecd1_det.ecd1_batch_pct = ps_batch_pct.

         end. /* IF AVAILABLE ps_mstr */

      end. /* ELSE */

   end. /* IF ecd1new */

   if not formula then
      assign
         ecd1_qty_type = ""
         ecd1_batch_pct = 0.

   if ecd1__qad04 = "1" then
      psmand = true1.
   else
      psmand = false1.

   if ecd1__qad05 = "1" then
      psdflt = true1.
   else
      psdflt = false1.

   if ecd1_cmtindx <> 0 then
      ecdcmmts = yes.
   display
      ecd1par
      ecd1comp
      ecd1ref
      ecd1qad01
      ecd1_qty_per_b
      l-um @ pt_um
      ecd1_scrp_pct
      ecd1_qty_type
      "B" when (ecd1new and formula) @ ecd1_qty_type
      ecd1_batch_pct
      ecd1_op
      ecd1_item_no
      ecd1__qad03
      psmand
      psdflt
      ecd1_rmks
      ecdcmmts
      ecd1_lt_off
      ecd1_fcst_pct
      ecd1_group
      ecd1_psprocess
   with frame form06.

   ststatus = stline[2].
   status input ststatus.
   del-yn = no.

   set1:
   do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


      set
         ecd1_qty_per_b
            when (ecd1_qty_type <> "P" and not deact)
         ecd1_qty_type
            validate (can-do("B,P,", ecd1_qty_type), l-msg2)
            when (formula and ecd1new and not deact)
         ecd1_batch_pct when (formula and not deact and
                             (ecd1new or ecd1_qty_type ="P"))
         ecd1__qad03
            when (not deact)
         psmand
            when (not deact)
         psdflt
            when (not deact)
         ecd1_rmks
            when (not deact)
         ecdcmmts
         ecd1_scrp_pct
            when (not deact)
         ecd1_lt_off
            when (not deact)
         ecd1_op
            when (not deact)
         ecd1_item_no
            when (not deact)
         ecd1_fcst_pct
            validate ((ecd1_fcst_pct >= 0 and ecd1_fcst_pct <= 100),
                       l-msg4)
            when (not deact)
         ecd1_group
            when (not deact)
         ecd1_psprocess
            when (not deact)

      go-on ("F5" "CTRL-D") with frame form06.

      if ecd1_batch_pct <> 0 and ecd1_qty_type <> "P" then do:
         /* TYPE MUST BE 'P' TO ENTER PERCENT OF BATCH */
         {pxmsg.i &MSGNUM=4602 &ERRORLEVEL=3}
         next-prompt ecd1_qty_type with frame form06.
         undo set1, retry.
      end. /* IF ecd1_batch_pct <> 0 */

      /* ENSURES THAT THE PCR/PCO MODULE CREATES/MODIFIES PRODUCT */
      /* STRUCTURES WITH STRUCTURE TYPE P, O, D AND X ONLY        */
      if  index("PODX", ecd1__qad03) = 0
      and ecd1__qad03 <> " "
      then do:

         /* MUST BE P, O, D, X OR BLANK */
         {pxmsg.i &MSGNUM=4087 &ERRORLEVEL=3}
         next-prompt ecd1__qad03 with frame form06.
         undo set1, retry set1.

      end. /* IF INDEX("PODXR", ecd1__qad03) = 0 */

      if ecd1_qty_type = "P"
      then
         batch_um = "".

         find bom_mstr where bom_par = ecd1par no-lock no-error.
         if available bom_mstr and bom_batch_um <> "" then
            batch_um = bom_batch_um.
         else do:
            find pt_mstr where pt_part = ecd1par no-lock no-error.
            if available pt_mstr then
               batch_um = pt_um.
         end. /* ELSE */

         conv = 1.
         if l-um             <> batch_um
            and ecd1_qty_type = "P"
         then do:
            {gprun.i ""gpumcnv.p""
               "(l-um, batch_um, ecd1comp, output conv)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            if conv = ? and ecd1_qty_type = "P" then do:
               /* COMPONENT UM IS DIFFERENT FROM PARENT UM */
               {pxmsg.i &MSGNUM=4600 &ERRORLEVEL=4}
               /* NO UNIT OF MEASURE CONVERSION EXISTS */
               {pxmsg.i &MSGNUM=33 &ERRORLEVEL=4}
               undo set1, retry.
            end. /* IF conv = ? */
         end. /* batch_um <> "" */

      if formula and ecd1_qty_type = "P" then do:
         ecd1_qty_per_b = ecd1_batch_pct * 0.01 * batch_size / conv.
         display
            ecd1_qty_per_b
         with frame form06.

      end. /* IF formula */

      ecd1__qad01 = ecd1qad01.

      if ecd1_qty_type = "B" or ecd1_qty_type = "P"
      then
         ecd1_qty_per = ecd1_qty_per_b / if bombatch = 0 then 1
                                         else bombatch.
      else
         ecd1_qty_per = ecd1_qty_per_b.
      assign
         ecd1_batch    = bombatch
         ecd1_batch_um = bombatchum.

      if ecd1__qad03 <> "O" and not deact
      and (not psmand or not psdflt)
      then do:
         /*REQUIRES STRUCTURE TYPE OF "O"*/
         {pxmsg.i &MSGNUM=5656 &ERRORLEVEL=3}
         if not psmand then next-prompt psmand with frame form06.
         else next-prompt psdflt with frame form06.
         undo set1, retry.
      end. /* IF ecd1__qad03 <> "O" */

      /* DELETE */
      if lastkey = keycode("F5") or lastkey = keycode("CTRL-D")
      then do:
         hide message no-pause.
         del-yn = yes.
         /* PLEASE CONFIRM DELETE */
         {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
         if del-yn = no then undo, retry.

         for each cmt_det exclusive-lock
            where  cmt_indx = ecd1_cmtindx:
            delete cmt_det.
         end. /* FOR EACH cmt_det */

         delete ecd1_det.
         del-yn = no.

         /* RECORD DELETED */
         {pxmsg.i &MSGNUM=22 &ERRORLEVEL=1}
         next mainloop.

      end. /* IF LASTKEY = KEYCODE("F5") */

      if ecdcmmts = yes then
      set3:
      do on error undo set3, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         pause 0.
         global_ref = ecd1_par + " / " + substring(ecd1_nbr,1,8).
         cmtindx = ecd1_cmtindx.
         {gprun.i ""gpcmmt03.p"" "(input ""ecd1_det"")"}
/*GUI*/ if global-beam-me-up then undo, leave.

         ecd1_cmtindx = cmtindx.
         global_ref = "".
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* IF ecdcmmts = YES */

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* set1 */

   assign
      ecd1__qad03 = ecd1__qad03
      ecd1__qad04 = ecd1__qad04
      ecd1__qad05 = ecd1__qad05
      ecd1__qad04 = string(integer(psmand))
      ecd1__qad05 = string(integer(psdflt))
      ecd1_process = prog_type.

   /* CHECK FOR  CYCLIC PRODUCT STRUCTURES  */
   {eccyck.i}

   run cyclic_check
      (input  ecd1_par,
      input  ecd1_comp,
      input  ecd1_ref,
      output ps_ok).

   if not ps_ok then do:
      hide message no-pause.
      /* CYCLIC PRODUCT STRUCTURE NOT ALLOWED. */
      {pxmsg.i &MSGNUM=2172 &ERRORLEVEL=2}
   end. /* IF NOT ps_ok */

end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* END OF mainloop */

status input.
